package com.teach.clone;

import java.util.Objects;

/**
 * <pre>
 * -
 * Author : J.L.Zhou
 * E-Mail : 2233875735@qq.com
 * Tel : 151 1104 7708
 * Date : 2021-04-13 15:16
 * Version : 1.0
 * Copyright 2021 jlzhou.top Inc. All rights reserved.
 * Warning: this content is only for internal circulation of the company.
 *          It is forbidden to divulge it or use it for other commercial purposes.
 * </pre>
 **/
public class Student implements Cloneable {
	private String name;

	private int age;
	
	private ClassInfo classInfo;

	public Student(String name) {
		this.name = name;
	}

	public Student(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}
	
	
	
	
	
	

	public ClassInfo getClassInfo() {
		return classInfo;
	}

	public void setClassInfo(ClassInfo classInfo) {
		this.classInfo = classInfo;
	}

	@Override
	protected Student clone() throws CloneNotSupportedException {
//		return (Student)super.clone();//浅度克隆
		Student s = (Student)super.clone();
		s.setClassInfo(classInfo.clone());//深度克隆
		return s;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	/**
	 * 对象被回收之前调用的
	 * 
	 * @throws Throwable
	 */
	@Override
	protected void finalize() throws Throwable {
		System.out.println("正在销毁:" + this);
	}
	

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		Student student1 = (Student) o;

		if (age != student1.age)
			return false;
		return name.equals(student1.name);
	}

	@Override
	public int hashCode() {
//    int result = name.hashCode();
//    result = 31 * result + age;
//    return result;
		return Objects.hash(name, age);
	}

	@Override
	public String toString() {
		return "Student [name=" + name + ", age=" + age + "]";
	}

}
